package com.hongning.railway.data;

import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;


import com.hongning.railway.entity.LoginEntity;
import com.hongning.railway.entity.reqbean.MettingMessageBean;
import com.hongning.railway.entity.reqbean.QueryCpInfoRequestBean;
import com.hongning.railway.entity.reqbean.QuestionRequestListBean;
import com.hongning.railway.entity.reqbean.QuestionResultBean;
import com.hongning.railway.entity.reqbean.QuestionResultListBean;
import com.hongning.railway.entity.reqbean.ReqAddExamScore;
import com.hongning.railway.entity.reqbean.ReqAddExperience;
import com.hongning.railway.entity.reqbean.ReqAddPages;
import com.hongning.railway.entity.reqbean.ReqAddScoreBean;
import com.hongning.railway.entity.reqbean.ReqAddViewOrPraise;
import com.hongning.railway.entity.reqbean.ReqAnswerCheck;
import com.hongning.railway.entity.reqbean.ReqAnswerSubmit;
import com.hongning.railway.entity.reqbean.ReqAssessesIntegral;
import com.hongning.railway.entity.reqbean.ReqAssessesIntegralBean;
import com.hongning.railway.entity.reqbean.ReqCadreListBean;
import com.hongning.railway.entity.reqbean.ReqCategory;
import com.hongning.railway.entity.reqbean.ReqDynamicBean;
import com.hongning.railway.entity.reqbean.ReqExam;
import com.hongning.railway.entity.reqbean.ReqExperienceList;
import com.hongning.railway.entity.reqbean.ReqKaoHeBaseBean;
import com.hongning.railway.entity.reqbean.ReqKaoHeGroupBean;
import com.hongning.railway.entity.reqbean.ReqKaoHeListBean;
import com.hongning.railway.entity.reqbean.ReqMemberList;
import com.hongning.railway.entity.reqbean.ReqNewDetail;
import com.hongning.railway.entity.reqbean.ReqNewsBean;
import com.hongning.railway.entity.reqbean.ReqScoreBean;
import com.hongning.railway.entity.reqbean.ReqUpdateExperience;
import com.hongning.railway.entity.reqbean.ReqVideoBean;
import com.hongning.railway.entity.reqbean.RosterMainBean;
import com.hongning.railway.entity.reqbean.ThreesessionSanDoneLessonBean;
import com.hongning.railway.entity.reqbean.UpdatesignBean;
import com.hongning.railway.entity.resbean.BaseRes;
import com.hongning.railway.entity.resbean.BaseResCadreListBean;
import com.hongning.railway.entity.resbean.BaseResExam;
import com.hongning.railway.entity.resbean.DataBeanX;
import com.hongning.railway.entity.resbean.Fileterbean;
import com.hongning.railway.entity.resbean.NewsCategoryBean;

import com.hongning.railway.entity.resbean.ResAnswerCheck;
import com.hongning.railway.entity.resbean.ResAnswerSubmitBean;
import com.hongning.railway.entity.resbean.ResCadreBean;
import com.hongning.railway.entity.resbean.ResDetailScore;
import com.hongning.railway.entity.resbean.ResDynamicBean;
import com.hongning.railway.entity.resbean.ResExamCompleteBean;
import com.hongning.railway.entity.resbean.ResExamItem;
import com.hongning.railway.entity.resbean.ResExperienceBean;
import com.hongning.railway.entity.resbean.ResKaoHeBean;
import com.hongning.railway.entity.resbean.ResKaoHeListBean;
import com.hongning.railway.entity.resbean.ResListScoreDetailBean;
import com.hongning.railway.entity.resbean.ResMemberInfo;
import com.hongning.railway.entity.resbean.ResNewsBean;
import com.hongning.railway.entity.resbean.ResNewsDetail;
import com.hongning.railway.entity.resbean.ResOptionBean;
import com.hongning.railway.entity.resbean.ResPhotoItem;
import com.hongning.railway.entity.resbean.ResScoreRankBean;
import com.hongning.railway.entity.resbean.ResScoreRankInfo;
import com.hongning.railway.entity.resbean.ResVideoBean;
import com.hongning.railway.entity.resbean.UpdateUserInfoBean;

import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.http.BaseResponse;

/**
 * MVVM的Model层，统一模块的数据仓库，包含网络数据和本地数据（一个应用可以有多个Repositor）
 * Created by goldze on 2019/3/26.
 */
public class AppRepository extends BaseModel implements HttpDataSource, LocalDataSource {
    private volatile static AppRepository INSTANCE = null;
    private final HttpDataSource mHttpDataSource;

    private final LocalDataSource mLocalDataSource;

    private AppRepository(@NonNull HttpDataSource httpDataSource,
                          @NonNull LocalDataSource localDataSource) {
        this.mHttpDataSource = httpDataSource;
        this.mLocalDataSource = localDataSource;
    }

    public static AppRepository getInstance(HttpDataSource httpDataSource,
                                            LocalDataSource localDataSource) {
        if (INSTANCE == null) {
            synchronized (AppRepository.class) {
                if (INSTANCE == null) {
                    INSTANCE = new AppRepository(httpDataSource, localDataSource);
                }
            }
        }
        return INSTANCE;
    }

    @VisibleForTesting
    public static void destroyInstance() {
        INSTANCE = null;
    }


    @Override
    public Observable<BaseResponse<LoginEntity>> login(String username, String password) {
        return mHttpDataSource.login(username,password);
    }


    @Override
    public void saveUserName(String userName) {
        mLocalDataSource.saveUserName(userName);
    }

    @Override
    public void savePassword(String password) {
        mLocalDataSource.savePassword(password);
    }

    @Override
    public String getUserName() {
        return mLocalDataSource.getUserName();
    }

    @Override
    public String getPassword() {
        return mLocalDataSource.getPassword();
    }


    @Override
    public Observable<BaseResponse<List<NewsCategoryBean>>> getCategory(ReqCategory reqCategory) {
        return mHttpDataSource.getCategory(reqCategory);
    }

    @Override
    public Observable<BaseResponse<DataBeanX>> getNewsList(ReqNewsBean reqNewsBean) {
        return mHttpDataSource.getNewsList(reqNewsBean);
    }

    @Override
    public Observable<BaseResponse<List<ResNewsBean>>> getTop5(ReqNewsBean reqNewsBean) {
        return mHttpDataSource.getTop5(reqNewsBean);
    }

    @Override
    public Observable<BaseResponse<ResDynamicBean>> getNewsDynamicList(ReqDynamicBean info) {
        return mHttpDataSource.getNewsDynamicList(info);
    }

    @Override
    public Observable<BaseResponse<ResNewsDetail>> getNewsDetail(ReqNewDetail reqNewDetail) {
        return mHttpDataSource.getNewsDetail(reqNewDetail);
    }

    @Override
    public Observable<BaseResponse<BaseRes<List<ResPhotoItem>>>> getDynamicPhotos(ReqDynamicBean reqDynamicBean) {
        return mHttpDataSource.getDynamicPhotos(reqDynamicBean);
    }

    @Override
    public Observable<BaseResponse<BaseRes<List<ResVideoBean>>>> getVideoList(ReqVideoBean reqVideoBean) {
        return mHttpDataSource.getVideoList(reqVideoBean);
    }

    @Override
    public Observable<BaseResponse> logout() {
        return mHttpDataSource.logout();
    }

    @Override
    public Observable<BaseResponse<BaseResExam<ResExamItem>>> getExamList(ReqNewsBean reqNewsBean) {
        return mHttpDataSource.getExamList(reqNewsBean);
    }

    @Override
    public Observable<BaseResponse<List<ResExamCompleteBean>>> getExamCompleteList(ReqNewsBean reqNewsBean) {
        return mHttpDataSource.getExamCompleteList(reqNewsBean);
    }

    @Override
    public Observable<BaseResponse<BaseResExam<ResOptionBean>>> getquestionslist(ReqExam reqExam) {
        return mHttpDataSource.getquestionslist(reqExam);
    }

    @Override
    public Observable<BaseResponse<ThreesessionSanDoneLessonBean>> selectmeet(MettingMessageBean mettingMessageBean) {
        return mHttpDataSource.selectmeet(mettingMessageBean);
    }

    @Override
    public Observable<BaseResponse<ResAnswerSubmitBean>> answerSubmit(ReqAnswerSubmit reqAnswerSubmit) {
        return mHttpDataSource.answerSubmit(reqAnswerSubmit);
    }

    @Override
    public Observable<BaseResponse<BaseResExam<ResAnswerCheck>>> answerCheck(ReqAnswerCheck reqAnswerCheck) {
        return mHttpDataSource.answerCheck(reqAnswerCheck);
    }

    @Override
    public Observable<BaseResponse> updatesign(UpdatesignBean updatesignBean) {
        return mHttpDataSource.updatesign(updatesignBean);
    }
    
    @Override
    public Observable<BaseResponse<List<ThreesessionSanDoneLessonBean.DataBean>>> selectMessage(MettingMessageBean mettingMessageBean) {
        return mHttpDataSource.selectMessage(mettingMessageBean);
    }

    @Override
    public Observable<BaseResponse> addvieworPraise(ReqAddViewOrPraise reqAddViewOrPraise) {
        return mHttpDataSource.addvieworPraise(reqAddViewOrPraise);
    }

    @Override
    public Observable<BaseResponse<RosterMainBean>> selectCadreList(MettingMessageBean mettingMessageBean) {
        return mHttpDataSource.selectCadreList(mettingMessageBean);
    }

    @Override
    public Observable<BaseResponse<BaseResCadreListBean<ResCadreBean>>> getCadreList(ReqCadreListBean reqCadreListBean) {
        return mHttpDataSource.getCadreList(reqCadreListBean);
    }

    @Override
    public Observable<BaseResponse<List<ResMemberInfo>>> getCadreMemberList(ReqMemberList reqCadreListBean) {
        return mHttpDataSource.getCadreMemberList(reqCadreListBean);
    }

    @Override
    public Observable<BaseResponse<String>> submitCadreMember(ReqMemberList reqCadreListBean) {
        return mHttpDataSource.submitCadreMember(reqCadreListBean);
    }

    @Override
    public Observable<BaseResponse<String>> addScore(ReqAddScoreBean reqAddScoreBean) {
        return mHttpDataSource.addScore(reqAddScoreBean);
    }

    @Override
    public Observable<BaseResponse<ResScoreRankInfo>> scoreRank(ReqScoreBean reqScoreBean) {
        return mHttpDataSource.scoreRank(reqScoreBean);
    }

    @Override
    public Observable<BaseResponse<ResDetailScore>> ScoreDetail(ReqScoreBean reqScoreBean) {
        return mHttpDataSource.ScoreDetail(reqScoreBean);
    }

    @Override
    public Observable<BaseResponse<Boolean>> addExperience(ReqAddExperience reqAddExperience) {
        return mHttpDataSource.addExperience(reqAddExperience);
    }

    @Override
    public Observable<BaseResponse<ResExperienceBean>> getExperienceList(ReqExperienceList reqExperienceList) {
        return mHttpDataSource.getExperienceList(reqExperienceList);
    }

    @Override
    public Observable<BaseResponse<Boolean>> updateExperience(ReqUpdateExperience reqUpdateExperience) {
        return mHttpDataSource.updateExperience(reqUpdateExperience);
    }

    @Override
    public Observable<BaseResponse<List<QuestionResultBean>>> selectAssessesIntegral(ReqAssessesIntegral reqAssessesIntegral) {
        return mHttpDataSource.selectAssessesIntegral(reqAssessesIntegral);
    }

    @Override
    public Observable<BaseResponse<String>> addAssessesIntegral(ReqAssessesIntegralBean reqAssessesIntegral) {
        return mHttpDataSource.addAssessesIntegral(reqAssessesIntegral);
    }

    @Override
    public Observable<BaseResponse<String>> saveAssessesIntegral(ReqAssessesIntegralBean reqAssessesIntegral) {
        return mHttpDataSource.saveAssessesIntegral(reqAssessesIntegral);
    }

    @Override
    public Observable<BaseResponse<List<ResScoreRankBean>>> allrankScore(ReqScoreBean reqScoreBean) {
        return mHttpDataSource.allrankScore(reqScoreBean);
    }

    @Override
    public Observable<BaseResponse<List<ResScoreRankBean>>> zhiburankScore(ReqScoreBean reqScoreBean) {
        return mHttpDataSource.zhiburankScore(reqScoreBean);
    }

    @Override
    public Observable<BaseResponse<List<ResScoreRankBean>>> allHnrankScore(ReqScoreBean reqScoreBean) {
        return mHttpDataSource.allHnrankScore(reqScoreBean);
    }

    @Override
    public Observable<BaseResponse<List<ResScoreRankBean>>> zhibuHnrankScore(ReqScoreBean reqScoreBean) {
        return mHttpDataSource.zhibuHnrankScore(reqScoreBean);
    }

    @Override
    public Observable<BaseResponse<List<ResKaoHeBean>>> getPartyExamInfoListForApp(ReqKaoHeListBean reqAssessesIntegral) {
        return mHttpDataSource.getPartyExamInfoListForApp(reqAssessesIntegral);
    }

    @Override
    public Observable<BaseResponse<List<ResKaoHeBean>>> getPartyExamInfoDetailsById(ReqKaoHeGroupBean reqAssessesIntegral) {
        return mHttpDataSource.getPartyExamInfoDetailsById(reqAssessesIntegral);
    }

    @Override
    public Observable<BaseResponse<QuestionResultListBean>> selectStatisticsByPage(QuestionRequestListBean questionRequestListBean) {
        return mHttpDataSource.selectStatisticsByPage(questionRequestListBean);
    }

    @Override
    public Observable<BaseResponse<String>> saveCadreMember(ReqMemberList reqCadreListBean) {
        return mHttpDataSource.saveCadreMember(reqCadreListBean);
    }

    @Override
    public Observable<BaseResponse<ResKaoHeListBean>> selectTestScoreAPP(ReqKaoHeBaseBean reqAssessesIntegral) {
        return mHttpDataSource.selectTestScoreAPP(reqAssessesIntegral);
    }

    @Override
    public Observable<BaseResponse<ReqAssessesIntegralBean>> selectAssessesIntegralById(QueryCpInfoRequestBean queryCpInfoRequestBean) {
        return mHttpDataSource.selectAssessesIntegralById(queryCpInfoRequestBean);
    }

    @Override
    public Observable<BaseResponse<LoginEntity>> updateStaffInfo(UpdateUserInfoBean updateUserInfoBean) {
        return mHttpDataSource.updateStaffInfo(updateUserInfoBean);
    }

    @Override
    public Observable<BaseResponse<List<Fileterbean>>> getTypesForApp() {
        return mHttpDataSource.getTypesForApp();
    }

    @Override
    public Observable<BaseResponse<ResScoreRankInfo>> getScoreRank(ReqScoreBean reqScoreBean) {
        return mHttpDataSource.getScoreRank(reqScoreBean);
    }

    @Override
    public Observable<BaseResponse<String>> addExamScore(ReqAddExamScore reqAddExamScore) {
        return mHttpDataSource.addExamScore(reqAddExamScore);
    }

    @Override
    public Observable<BaseResponse> addPageView(ReqAddPages reqAddPages) {
        return mHttpDataSource.addPageView(reqAddPages);
    }
}
